﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using NSubstitute;

namespace GearUp.Crawler.Tests
{
    public class CrawlerTests
    {
        private const string ItemCategoryUrl = "http://lorebook.lotro.com/wiki/Category:Items";
        private const string ArmourUrl = "http://lorebook.lotro.com/wiki/Category:Armour";

        [Fact]
        public void ShouldOnlyCrawlAPageOnlyOnce()
        {
            //var repository = Substitute.For<ILoreBookItemRepository>();
            //var parser = Substitute.For<ILorebookItemParser>();
            //var linkManager = new LinkManager("");
            //var crawler = new Crawler(repository, parser, linkManager);
            //pageLoader.LoadPageContent(ItemCategoryUrl).Returns(Resource1.CategoryItemsHtml);
            //var result = crawler.LoadUrl(ItemCategoryUrl);
            //Assert.False(string.IsNullOrEmpty(result));
            //result = crawler.LoadUrl(ItemCategoryUrl);
            //Assert.True(string.IsNullOrEmpty(result));
        }

        [Fact]
        public void ShouldAddLoreBookItemsToStorage()
        {
            //var pageLoader = Substitute.For<IPageLoader>();
            //var repository = Substitute.For<ILoreBookItemRepository>();
            //var parser = Substitute.For<ILorebookItemParser>();
            //var linkManager = new LinkManager("");
            //var crawler = new Crawler(pageLoader, repository, parser, linkManager);
            //pageLoader.LoadPageContent(ItemCategoryUrl).Returns(Resource1.CategoryItemsHtml);
            //pageLoader.LoadPageContent(ArmourUrl).Returns(Resource1.ArmourPageHtml);
            //crawler.StartCrawl(ItemCategoryUrl);
        }

        [Fact]
        public void ShouldExtractItemInfoFromCrawledPages()
        {
            //var pageLoader = Substitute.For<IPageLoader>();
            //var repository = Substitute.For<ILoreBookItemRepository>();
            //var parser = new LorebookItemParser();
            //var linkManager = new LinkManager("");
            //var crawler = new Crawler(pageLoader, repository, parser, linkManager);
            //pageLoader.LoadPageContent(ItemCategoryUrl).Returns(Resource1.ArmourPageHtml);
            //var lorebookDocument = new LorebookDocument(crawler.LoadUrl(ItemCategoryUrl));
            //var item = crawler.ExtractLoreBookItem(lorebookDocument, ItemCategoryUrl);
            //Assert.NotNull(item);
            //Assert.Equal(ItemCategoryUrl, item.ItemUrl);
        }
    }
}
